package com.zzzzzz.oms.tempShipment;

import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zzzzzz.core.datagrid.BaseData;
import com.zzzzzz.core.datagrid.BaseQueryForm;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.zzzzzz.plugins.shiro.ShiroUtils;

/**
 * @author hing
 * @version 1.0.0
 */
@Controller
public class TempShipmentWeb {

	@Resource
	public TempShipmentService tempShipmentService;
	@Resource
	public TempShipmentDao tempShipmentDao;

	@RequestMapping(value = "/tempShipment/list", method = RequestMethod.GET)
	public String list() {
		return "oms/tempShipment";
	}

	@RequestMapping(value = "/tempShipment/save", method = RequestMethod.POST)
	@ResponseBody
	public BaseData save(@RequestBody @Valid TempShipment tempShipment,@RequestParam(value = "vocationType", required = true) String vocationType,@RequestParam(value = "ids", required = true) List<Long> ids,@RequestParam(value = "tempshipmentId", required = true) Long tempshipmentId) throws Exception {
		TempShipment tempShipment1=tempShipmentService.save(tempShipment,vocationType,ids, tempshipmentId, ShiroUtils.findUser());
		return new BaseData(tempShipment1, null);
	}
	  
	@RequestMapping(value = "/tempShipment/updStByIds", method = RequestMethod.POST)
	@ResponseBody
	public BaseData updStByIds(@RequestBody @Valid TempShipment tempShipment, BindingResult bindingResult) throws Exception {
		tempShipmentDao.updStByIds(tempShipment,ShiroUtils.findUser());
		return new BaseData("0");
	}
	
	@RequestMapping(value = "/tempShipment/updStById", method = RequestMethod.POST)
	@ResponseBody
	public BaseData updStById(@RequestParam(value = "id", required = true) Long id, @RequestParam(value = "quantity", required = true) Double quantity,@RequestParam(value = "points", required = true) Integer points,@RequestParam(value = "weight", required = true) Double weight,@RequestParam(value = "volume", required = true) Double volume,@RequestParam(value = "count", required = true) Integer count) throws Exception {
		tempShipmentDao.updStById(id,quantity,points,weight,volume,count,ShiroUtils.findUser());
		return new BaseData("0");
	}
	@RequestMapping(value = "/tempShipment/updStatusById", method = RequestMethod.POST)
	@ResponseBody
	public BaseData updStatusById(@RequestParam(value = "id", required = true) Long id) throws Exception {
		tempShipmentDao.updStatusById(id,ShiroUtils.findUser());
		return new BaseData("0");
	}	
	
	
	@RequestMapping(value = "/tempShipment/delById", method = RequestMethod.POST)
	@ResponseBody
	public BaseData delById(@RequestParam(value = "ids", required = true) List<Long> ids) throws Exception {
		tempShipmentDao.delById(ids);
		return new BaseData("0");
	}	
	
	@RequestMapping(value = "/tempShipment/id/{id}", method = RequestMethod.GET)
	@ResponseBody 
	public BaseData findById(@PathVariable Long id) {
		TempShipment tempShipment = tempShipmentDao.findById(id);
		return new BaseData(tempShipment, null);
	}
	@RequestMapping(value = "/tempShipment/findByIds", method = RequestMethod.POST)
	@ResponseBody 
	public BaseData findByIds(@RequestParam(value = "ids", required = true)List<Long> ids) {
		tempShipmentService.cancel(ids, ShiroUtils.findUser());
		return new BaseData("0");
	}
	
	@RequestMapping(value = "/tempShipment/saveByIds", method = RequestMethod.POST)
	@ResponseBody 
	public BaseData saveByIds(@RequestParam(value = "ids", required = true)List<Long> ids) {
		tempShipmentService.saveShipment(ids, ShiroUtils.findUser());
		return new BaseData("0");
	}
	
	@RequestMapping(value = "/tempShipment/findListBy", method = RequestMethod.POST)
	@ResponseBody
	public BaseData findListBy(@RequestBody BaseQueryForm baseQueryForm) {
		List<Map<String, Object>> list = tempShipmentDao.findListBy(baseQueryForm.getFfMap(),ShiroUtils.findUser());
		return new BaseData(list, null);
	}
	
	
	//根据波次自动配载
	
	@RequestMapping(value = "/tempShipment/bczdpz", method = RequestMethod.POST)
	@ResponseBody
	public BaseData bczdpz(@RequestParam(value = "tempshipmentId", required = true)Long tempshipmentId) {
		tempShipmentService.findGroupByWaveIds(tempshipmentId, ShiroUtils.findUser());
		return new BaseData("0");
	}
    
	//根据波次自动配车
	
	@RequestMapping(value = "/tempShipment/bczdpc", method = RequestMethod.POST)
	@ResponseBody
	public BaseData bczdpc(@RequestParam(value = "vocation", required = true)String vocationType) {
		tempShipmentService.bczdpc(vocationType,ShiroUtils.findUser());
		return new BaseData("0");
	}
	
	//增加订单
	@RequestMapping(value = "/tempShipment/zjdd", method = RequestMethod.POST)
	@ResponseBody
	public BaseData zjdd(@RequestParam(value = "tempshipmentId", required = true)Long tempshipmentId,@RequestParam(value = "tempshipmentId1", required = true)Long tempshipmentId1,@RequestParam(value = "legsIds", required = true)List<Long> legsIds) {
		tempShipmentService.zjdd(tempshipmentId, tempshipmentId1, legsIds, ShiroUtils.findUser());
		return new BaseData("0");
	}
	
	//取消高级调度调度单
	@RequestMapping(value = "/tempShipment/qxdd", method = RequestMethod.POST)
	@ResponseBody
	public BaseData qxdd(@RequestParam(value = "tempshipmentId", required = true)Long tempshipmentId,@RequestParam(value = "tempshipmentId1", required = true)Long tempshipmentId1,@RequestParam(value = "legsIds", required = true)List<Long> legsIds) {
		tempShipmentService.qxdd(tempshipmentId, tempshipmentId1, legsIds, ShiroUtils.findUser());
		return new BaseData("0");
	}
	
    private static final Logger logger = LoggerFactory.getLogger(TempShipmentWeb.class);
}
